class UserController < ApplicationController

    def index
        list
        render :action => 'list'
    end
    
    # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
    verify :method => :post, :only => [ :destroy, :create, :update ],
    :redirect_to => { :action => :list }
    
    def user_list
        @user_pages, @users = paginate :users, :per_page => 10
    end
    
    def user_show
        @user = User.find(params[:id])
    end
    
    def user_new
        @user = User.new
    end
    
    def user_create
        @user = User.new(params[:user])
        if @user.save
            flash[:notice] = 'User was successfully created.'
            redirect_to :action => 'list'
        else
            render :action => 'user_new'
        end
    end
    
    def users_edit
        
    end
    
    def users_update
 	redirect_to :action => 'users_edit'
    end
    
    def users_add
        @user = User.find_first(["username = ?", params[:user][:username]])
        if @user
            @newsite.users.push_with_attributes(user, :role_id => Role.admin.id)
        else
            flash[:error] = 'User could not be found.'
        end 
        redirect_to :action => 'users_edit'
    end
    
    def user_destroy
        User.find(params[:id]).destroy
        redirect_to :action => 'user_list'
    end
end
